using System.Collections;
using Awaiter;
using Canvas.ImageRotate;
using YesPlayLove.Classes;
using jQueryApi;
using Yoshi.Classes;

namespace YoshiFlowMain
{
    //[IgnoreNamespace] Don't use because full class name is used in Master.cs to find this class
    public sealed class GamesPage : YoshiPage
    {
        private jQueryObject _outer;
        private jQueryObject _worms;

        public GamesPage()
        {
            new Await().AddAw(BasicBuildAw, GamesTheme.PageTitle).Commit();
        }

        public override void RefreshAw(Await awp)
        {
            _outer = jQuery.FromHtml("<div/>").AppendTo(PageCluster)
                ;

            _worms = jQuery.FromHtml("<div style='position:absolute;top:0;left:0;width:100%;height:100%;opacity:.15'/>")
                .PrependTo("#PageContent")
                .Append(jQuery.FromHtml("<canvas style='width:100%;height:100%'/>"))
                ;

            new Await()
                .AddDx(
                    delegate
                    {
                        jQuery.FromHtml("<a href='http://www.stumbleupon.com/su/2Laj6v/butchersworkshop.com/witr/' target='_blank'>Find the red game</a>")
                            .CSS(new Dictionary("margin-left", "50px", "color", "#800"))
                            .AppendTo(_outer)
                            ;

                        //jQuery.FromHtml("<br/>").AppendTo(_outer);

                        //jQuery.FromHtml("<img/>")
                        //    .AppendTo(_outer)
                        //    .Attribute("src", "images/Common/EmotionalScale.png")
                        //    .Attribute("height", "800")
                        //    ;

                        new EmotionalScale().AppendTo(_outer).Prepend(
                            jQuery.FromHtml("<h3/>").Html("The Emotional Scale")
                            );

                        new Await()
                            .LoadScript("Scripts/Worms/Worms.js")
                            .AddDx(delegate { jQuery.Select("canvas", _worms).Plugin<Worms>().WormFill(); })
                            .Commit();
                    }
                )
                .Commit(awp);
        }

        public override void Destroy()
        {
            jQuery.Select("canvas", _worms).Plugin<Worms>().WormKill();
        }

        public void DeleteAw(Await awp, jQueryObject elToDel)
        {
            awp.Done();
        }

    }
}